package com.weimob.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: xh-learn-record
 * @description:
 * @author: sch
 * @create: 2022-12-17 18:17
 **/
@RestController
@RequestMapping("kafka")
@Slf4j
public class KafkaController {
    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    @RequestMapping("test")
    public String test() {
        return "hello kafka";
    }

    @GetMapping("send")
    public void send() {
        String message = "你好，我是xhx";
        // 第一个参数 topic
        // 第二个参数 消息
        kafkaTemplate.send("first-topic", message);

        log.info("------log------:{}", message);
    }
}
